/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bff.slimserver.musicjukebox.ui.components.podcast;


import com.bff.bjj.ui.component.MusicList;
import com.bff.slimserver.music.exceptions.PlaylistException;
import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ListSelectionModel;
import org.bff.slimserver.SlimPlaylist;
import org.bff.slimserver.SlimPodcaster;
import org.bff.slimserver.musicobjects.SlimPodcastItem;
import org.bff.slimserver.exception.SlimConnectionException;

/**
 *
 * @author bfindeisen
 */
public class PodcastList extends MusicList {

    private SlimPodcaster podcaster;
    private SlimPlaylist playlist;
    private PodcastListCellRenderer podcastListCellRenderer;

    public PodcastList() {
        try {
            playlist = JukeboxProperties.getInstance().getPlaylist();
        } catch (PlaylistException ex) {
            Logger.getLogger(PodcastList.class.getName()).log(Level.SEVERE, null, ex);
        }

        try {
            setPodcaster(JukeboxProperties.getInstance().getPodcaster());
        } catch (SlimConnectionException ex) {
            Logger.getLogger(PodcastList.class.getName()).log(Level.SEVERE, null, ex);
        }

        setPodcastListCellRenderer(new PodcastListCellRenderer());
        setCellRenderer(getPodcastListCellRenderer());

        setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        //listAll();
        //addMouseListener(this);

    }


    public void listAll() {
//        try {
//            podcastListModel.clear();
//
//            podcastList = new ArrayList<SlimPodcastItem>(getPodcaster().getAllPodcasts());
//
//            for (SlimPodcastItem podcast : podcastList) {
//                podcastListModel.addElement(podcast);
//            }
//
//            setModel(podcastListModel);
//            setSelectedIndex(0);
//        } catch (Exception e) {
//            e.printStackTrace();
//            new ErrorDialog(Utils.getParentComponent(this), "Could not get podcast list.", e, false, false);
//        }
    }

    public SlimPodcastItem getSelectedPodcast() {
        return (SlimPodcastItem) getSelectedValue();
    }

    public SlimPlaylist getPlaylist() {
        return playlist;
    }

    public void setPlaylist(SlimPlaylist playlist) {
        this.playlist = playlist;
    }

    /**
     * @return the podcaster
     */
    public SlimPodcaster getPodcaster() {
        return podcaster;
    }

    /**
     * @param podcaster the podcaster to set
     */
    public void setPodcaster(SlimPodcaster podcaster) {
        this.podcaster = podcaster;
    }

    /**
     * @return the podcastListCellRenderer
     */
    public PodcastListCellRenderer getPodcastListCellRenderer() {
        return podcastListCellRenderer;
    }

    /**
     * @param podcastListCellRenderer the podcastListCellRenderer to set
     */
    public void setPodcastListCellRenderer(PodcastListCellRenderer podcastListCellRenderer) {
        this.podcastListCellRenderer = podcastListCellRenderer;
    }
}
